using System;
using System.Text;
using Microsoft.SPOT;
using System.Threading;

namespace ReefinDotNet
{
    partial class Program
    {
        public void calculateLights()
        {
            //Debug.Print("Lighting starting on thread: " + Thread.CurrentThread.ManagedThreadId);
            double[] day1 = new double[] { -0.0346, 2.5909, -69.363, 763.25, -2716.8, 11.33 };
            double CurrentPower;
            double calcTime;
            //double[] day1 = new double[] { 0, 0, 0, 0, 0, 0};
            while (true)
            {
                try
                {
                    CurrentPower = day1[5];
                    calcTime = DateTime.Now.Hour; // hours in 24 hour format
                    calcTime += (((double)(DateTime.Now.Minute) / 60)); // convert minutes to fractional hours
                    CurrentPower += day1[4] * calcTime;
                    CurrentPower += day1[3] * System.Math.Pow(calcTime, 2);
                    CurrentPower += day1[2] * System.Math.Pow(calcTime, 3);
                    CurrentPower += day1[1] * System.Math.Pow(calcTime, 4);
                    CurrentPower += day1[0] * System.Math.Pow(calcTime, 5);
                    if (CurrentPower < 0)
                        CurrentPower = 0;
                    int SetPower = (int)(CurrentPower);
                    caclLights[0] = SetPower * 1.20;
                    caclLights[1] = SetPower * 1.50;
                    if (caclLights[1] < 10)
                        caclLights[1] = 10;
                    caclLights[2] = SetPower * 1.50;
                    caclLights[3] = SetPower * 1.50;
                    caclLights[4] = SetPower * 1.20;
                    if (mainLights.Override != true)
                    {
                        mainLights.fadeTo((int)(caclLights[0]), (int)(caclLights[1]), (int)(caclLights[2]), (int)(caclLights[3]), (int)(caclLights[4]), 2);
                    }
                }
                catch (Exception ex)
                {
                    Debug.Print(ex.ToString());
                }
                Thread.Sleep(3000);
            }
        }
    }
}